package com.irmasoft.flagquiz;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;


public class FlagUtils {
	
	public static final String flagList ="afghanistan,albania,algeria,andorra,angola,argentina,armenie,australia,autriche," +
								 "azerbaidjan,bahrein,bangladesh,belarus,belgique,belize,benin,bolivia,bosniaandherzegovina," +
								 "botswana,brazil,canada,germany,iceland,iraq,myanmar,saudiearabia,southafrica,tunsia,turkey,unitedkingdom";
	
	public static List<String> getFlags(){
		String[] flags = flagList.split(",");
		List<String> lFlags = new ArrayList<String>();
		for(String flag : flags){
			lFlags.add(flag);
		}
		return lFlags;
	}
	
	public static String fileScore = "score.properties";
	
	public static Map<String, Drawable> getDrawableFlag(Context context){
		Map<String, Drawable> flagMap = new HashMap<String, Drawable>();
		flagMap.put("afghanistan", resize(context.getResources().getDrawable(R.drawable.afghanistan)));
		flagMap.put("albania", resize(context.getResources().getDrawable(R.drawable.albania)));
		flagMap.put("algeria", resize(context.getResources().getDrawable(R.drawable.algeria)));
		flagMap.put("andorra", resize(context.getResources().getDrawable(R.drawable.andorra)));
		flagMap.put("angola", resize(context.getResources().getDrawable(R.drawable.angola)));
		flagMap.put("argentina", resize(context.getResources().getDrawable(R.drawable.argentina)));
		flagMap.put("armenie", resize(context.getResources().getDrawable(R.drawable.armenie)));
		flagMap.put("australia", resize(context.getResources().getDrawable(R.drawable.australia)));
		flagMap.put("autriche", resize(context.getResources().getDrawable(R.drawable.autriche)));
		flagMap.put("azerbaidjan", resize(context.getResources().getDrawable(R.drawable.azerbaidjan)));
		flagMap.put("bahrein", resize(context.getResources().getDrawable(R.drawable.bahrein)));
		flagMap.put("bangladesh", resize(context.getResources().getDrawable(R.drawable.bangladesh)));
		flagMap.put("belarus", resize(context.getResources().getDrawable(R.drawable.belarus)));
		flagMap.put("belgique", resize(context.getResources().getDrawable(R.drawable.belgique)));
		flagMap.put("belize", resize(context.getResources().getDrawable(R.drawable.belize)));
		flagMap.put("benin", resize(context.getResources().getDrawable(R.drawable.benin)));
		flagMap.put("bolivia", resize(context.getResources().getDrawable(R.drawable.bolivia)));
		flagMap.put("bosniaandherzegovina", resize(context.getResources().getDrawable(R.drawable.bosniaandherzegovina)));
		flagMap.put("botswana", resize(context.getResources().getDrawable(R.drawable.botswana)));
		flagMap.put("brazil", resize(context.getResources().getDrawable(R.drawable.brazil)));
		flagMap.put("canada", resize(context.getResources().getDrawable(R.drawable.canada)));
		flagMap.put("germany", resize(context.getResources().getDrawable(R.drawable.germany)));
		flagMap.put("iceland", resize(context.getResources().getDrawable(R.drawable.iceland)));
		flagMap.put("iraq", resize(context.getResources().getDrawable(R.drawable.iraq)));
		flagMap.put("myanmar", resize(context.getResources().getDrawable(R.drawable.myanmar)));
		flagMap.put("saudiearabia", resize(context.getResources().getDrawable(R.drawable.saudiearabia)));
		flagMap.put("southafrica", resize(context.getResources().getDrawable(R.drawable.southafrica)));
		flagMap.put("tunsia", resize(context.getResources().getDrawable(R.drawable.tunsia)));
		flagMap.put("turkey", resize(context.getResources().getDrawable(R.drawable.turkey)));
		flagMap.put("unitedkingdom", resize(context.getResources().getDrawable(R.drawable.unitedkingdom)));
		return flagMap;
	}
	
	private static Drawable resize(Drawable image) {
	    Bitmap d = ((BitmapDrawable)image).getBitmap();
	    Bitmap bitmapOrig = Bitmap.createScaledBitmap(d, 480, 240, false);
	    return new BitmapDrawable(bitmapOrig);
	}

}
